/*******************************************************\
|* Author: Trevor Sundberg
\*******************************************************/

// Header protection
#pragma once
#ifndef SKUGO_PACKET_ROUTER_HPP
#define SKUGO_PACKET_ROUTER_HPP

// Includes
#include "SkugoTypes.hpp"
#include "SkugoConnection.hpp"
#include "SkugoPlugin.hpp"
#include "SkugoPacket.hpp"
#include <vector>
#include <map>

namespace Skugo
{
  // Using directives
  using std::vector;
  using std::map;

  // Forward declarations
  class IConnection;
  class PluginContainer;

  // Communicates with the link and is responsible for sending and receiving
  // packets so that the plugins can communicate with their counterparts.
  // This class is separated from the IHost/IConnection interface to their implementation easier.
  class PacketRouter
  {
  public:

    // Constructor
    PacketRouter(IConnection* connection, PluginContainer* localPlugins);

    // Process all the incoming packets that are waiting
    void ProcessAllIncoming();

  private:

    // Get rid of assignment and copy
    PacketRouter& operator =(const PacketRouter&);
    PacketRouter(const PacketRouter&);

  private:

    // Store the link that we communicate with.
    IConnection* Connection;

    // The plugin container that contains the list of all local plugins.
    PluginContainer* LocalPlugins;
    
    // Store the size of the current packet.
    PacketHeader CurrentPacket;

    // Store all the read in data.
    vector<char> Data;
  };
}

// End header protection
#endif
